<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>客户端演示-1</title>
  <link rel="stylesheet" href="/layui/css/layui.css">
</head>
<body>

<form class="layui-form" action="">

  <div class="layui-form-item">
    <label class="layui-form-label">请输入旧密码</label>
    <div class="layui-input-inline">
      <input type="password" id="oldpwd" required lay-verify="required" placeholder="请输入旧密码" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">请输入新密码</label>
    <div class="layui-input-inline">
      <input type="password" id="newpwd" required lay-verify="required" placeholder="请输入新密码" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">确认新密码</label>
    <div class="layui-input-inline">
      <input type="password"  id="repwd" required lay-verify="required" placeholder="确认新密码" autocomplete="off" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="formDemo" id="submit">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
</body>
</html>
<script src="/layui/layui.js"></script>
<script src="/js/jquery-3.6.0.min.js" ></script>
<script src="/js/jq-cookie-1.1.js" ></script>
<script>

  /**************前端环境配置****************/
  // 产业UAT环境
  //var host_proc="http://spring-sso-client1-demo.chanyan-commonsafty-hantele:9001"
  // 测试环境
  //var host_proc="http://192.168.108.19:9002"
  //var host_proc="http://192.168.108.19:9001"
  // 本地环境
  var host_proc="http://client.com:9001"



  // -------------退出环境配置---------------
  //测试环境/opt/app/other环境
  //var logout_url="http://192.168.108.19:9096"
  //测试环境
  var logout_url="http://183.235.210.8:9095/logout"
  /**************前端环境配置****************/
  //Demo
  layui.use('form', function(){
    var form = layui.form;
    //监听提交
    form.on('submit(formDemo)', function(data){
      var oldpwd=$("#oldpwd").val()
      var newpwd=$("#newpwd").val()
      var repwd=$("#repwd").val()
      if(newpwd != repwd){
        layer.msg("两次输入的密码不一致")
        return false;
      }
        $.ajax({
          url: host_proc+"/reset/pwd",
          type: 'PUT',
          dataType : "json",
          contentType: 'application/json',
          data:JSON.stringify({
            "newPassword": newpwd,
            "oldPassword": oldpwd,
            "userName":$.cookie("username")
          }),
          headers: {
            "token": token
          },
          success: function (data) {
            //console.log(data)

            if(data["code"] == 200){
              layer.msg("修改成功")
              setTimeout(function () {
                window.location.href="/";
              },2000)
            }else{
              layer.msg("修改失败，请重试！")
            }
          },
          error: function (data) {
            //console.log(data)
            layer.msg("服务异常！")
          }
        });
      return false;
    });
  });

  //JS
  layui.use(['element', 'layer', 'util'], function(){
    var element = layui.element
            ,layer = layui.layer
            ,util = layui.util
            ,$ = layui.$;

    $(document).ready(function(){
      token = $.cookie("access_token");
    });

    element.init();

  });



</script>
